<?php

namespace App\Controllers;

class Movie extends BaseController {

    public function getIndex() {
        // connect to the model 
        $actors = new \App\Models\Actors();
        // retrieve all the records 
        $records = $actors->findAll();
        $table = new \CodeIgniter\View\Table();
        // get a template parser 
        $parser = \Config\Services::parser();
        // tell it about the substitions 
        $headings = $actors->fields;
        $displayHeadings = array_slice($headings, 1, 3);
        $table->setHeading(array_map('ucfirst', $displayHeadings));
        foreach ($records as $record) {
            $DLink = anchor("Movie/showme/$record->id", 'Detail');
            $table->addRow( $record->name,'<img src="/image/'.$record->image.'">',$DLink);
            
            
            $template = [
                'table_open' => '<table cellpadding="10px">',
                'cell_start' => '<td style="border: 1px solid #dddddd;">',
                'row_alt_start' => '<tr style="background-color:#dddddd">',
            ];
            $table->setTemplate($template);
            $fields = [
                'title' => 'Hong Kong Action Actor',
                'heading' => 'Hong Kong Action Actor',
                'footer' => 'Copyright ZhongJIngChong'
            ];
        }
        return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');

        
        $parser = \Config\Services::parser();
        return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');
        
    }

    public function getShowme($id) {
     $actors = new \App\Models\Actors();
        // retrieve all the records
        $record = $actors->find($id);
        // get a template parser
        $parser = \Config\Services::parser();
        // tell it about the substitions
        $table = new \CodeIgniter\View\Table();
        $table->addRow("id",$record['id']);
        $table->addRow("name",$record['name']);
        $table->addRow('city', $record['city']);
        $table->addRow('brandfilm', $record['brandfilm']);
        $table->addRow('constellation', $record['constellation']);
        $table->addRow('company', $record['company']);
        $table->addRow("link",$record['link']);
        $table->addRow("image",'<img src="/image/'.$record['image'].'"/>');
       
        
        $template = [
                'table_open' => '<table cellpadding="10px">',
                'cell_start' => '<td style="border: 1px solid #dddddd;">',
                'row_alt_start' => '<tr style="background-color:#dddddd">',
            ];
            $table->setTemplate($template);
            $fields = [
                'title' => 'Hong Kong Action Actor',
                'heading' => 'Actor Introduced',
                'footer' => 'Copyright ZhongJIngChong'
            ];
        return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');
    }

}
